package 线程.生产消费模型;

public class Box {
    private int size=0;
    private char[] boxlist = new char[3] ;
    private static int i;
    public synchronized void get(){
        while (this.size<=0){
            try {
                wait();
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        char ch = boxlist[--size];
        notify();
        System.out.println(ch+"被消费了");
    }
    public synchronized void set( ){
        while (this.size>=boxlist.length){
            try {
                wait();
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        boxlist[size++] = (char)(65+i);
        i++;
        if (i>=26) return;
        notify();
        System.out.println((char)(65+i)+"被生产了");
    }
}
